import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';

import './image_detail_page.dart';

/// 1. 创建全局 eventBus 对象
final eventBus = EventBus();

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Animation")),
      body: MyBody(),
    );
  }
}

class MyBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2, crossAxisSpacing: 8, mainAxisSpacing: 8, childAspectRatio: 16 / 9),
      children: List.generate(
        20,
        (index) {
          String src = "https://picsum.photos/200/300?random=$index";
          return GestureDetector(
            onTap: () {
              Navigator.of(context).push(
                PageRouteBuilder(
                  // transitionDuration: Duration(seconds: 1),
                  pageBuilder: (context, animation, secondaryAnimation) {
                    return FadeTransition(
                      opacity: animation,
                      child: ImageDetailPage(src: src),
                    );
                  },
                ),
              );
            },
            child: Hero(tag: src, child: Image.network(src, fit: BoxFit.cover)),
          );
        },
      ),
    );
  }
}
